package com.gbei.center.utils.message;

public enum ResponseInfo {
	
	SUCCESS(10000,"操作成功",true),
	SUCCESS_NOT_FOUND(20000,"数据为空",true),
	INVALID_REQUEST(10001,"invalid_request -- 请求缺少某个必需参数，包含一个不支持的参数或参数值，或者格式不正确",false),
	INVALID_CLIENT(10002,"invalid_client -- 请求的client_id或client_secret参数无效。",false),
	INVALID_GRANT(10003,"invalid_grant -- 请求的Authorization Code、Access Token、Refresh Token等信息是无效的",false),
	UNSUPPORTED_GRANT_TYPE(10004,"unsupported_grant_type -- 不支持的grant_type",false),
	INVALID_SCOPE(10005,"invalid_scope -- 请求的scope参数是无效的、未知的、格式不正确的",false),
	LACK_SCOPE(10006,"lack_scope -- 请求的权限范围超过了数据拥有者所授予的权限范围",false),
	EXPIRED_TOKEN(10007,"expired_token -- 请求的Access Token已过期",false),
	LACK_TOKEN(10008,"lack_token -- 请求缺少Access Token",false),
	REDIRECT_URI_MISMATCH(10009,"redirect_uri_mismatch -- 请求的redirect_uri所在的域名与开发者注册应用时所填写的域名不匹配",false),
	INVALID_TOKEN(10010,"invalid_token -- 请求的token不存在用户信息",false),
	FAILURE(-1,"操作失败！",false);


	private int code;
	private String message;
	private boolean success;
	
	 ResponseInfo(int code, String message, boolean success){
		this.code = code;
		this.message = message;
		this.success = success;
	}

	public int getCode() {
		return code;
	}

	public String getMessage(){
		return this.message;
	}
	public boolean getSuccess(){
		return this.success;
	}
	
	public void setCode(int code) {
		this.code = code;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public void setSuccess(boolean success) {
		this.success = success;
	}
	
	public <T> Result<T> messageToResult(){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		return result;
	}
	public <T> Result<?> messageToResult(Long time){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setVersion(time);
		return result;
	}
	
	public <T> Result<T> messageToResult(T obj){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setData(obj);
		return result;
	}
	
	public <T> Result<T> messageToResult(T obj,Long time){
		Result<T> result = new Result<T>();
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setData(obj);
		result.setVersion(time);
		return result;
	}
	
	public Result<?> messageToResult(Result<?> result){
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		return result;
	}

	public Result<?> messageToResult(Result<?> result,Long time){
		result.setCode(this.getCode());
		result.setSuccess(this.getSuccess());
		result.setMessage(this.getMessage());
		result.setVersion(time);
		return result;
	}
	
}
